package jlib.component.scroll
{
	import jlib.component.button.SkinButton;
	import jlib.component.scroll.skin.ScrollBarSkinFactory;
	
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.events.MouseEvent;

	public class HScrollBar extends ScrollBar
	{
		private var m_prevButton:InteractiveObject;
		private var m_nextButton:InteractiveObject;
		
		public function HScrollBar()
		{
			super();
			initPrevButton();
			initNextButton();
			setDirection(ScrollBarDirection.HORIZONTAL);
		}
		
		private function initPrevButton(): void
		{
			setPrevButton(ScrollBarSkinFactory.getHorizontalPrevButton());
		}
		
		private function initNextButton(): void
		{
			setNextButton(ScrollBarSkinFactory.getHorizontalNextButton());
		}
		
		/**
		 * Track 디스플레이 객체의 size 값을 설정합니다.
		 * @param sizePixel size값
		 */		
		override public function setTrackSize(sizePixel:Number): void 
		{ 
			m_prevButton.x = 0;
			m_nextButton.x = sizePixel-m_nextButton.width;
			m_track.x = m_prevButton.x+m_prevButton.width;
			m_directionState.setTrackSize(sizePixel-(m_prevButton.width+m_nextButton.width));
			if(m_isAutoRange) m_range = sizePixel;
			update();
		}
		
		public function getPrevButton(): InteractiveObject { return m_prevButton; }
		
		public function setPrevButton($button:InteractiveObject): void
		{
			if(m_prevButton) {
				if(contains(m_prevButton)) removeChild(m_prevButton);
				m_prevButton.removeEventListener(MouseEvent.CLICK, decrease );
			}
			m_prevButton = $button;
			addChild(m_prevButton);
			m_prevButton.addEventListener(MouseEvent.CLICK, decrease  );
		}
		
		public function getNextButton(): InteractiveObject { return m_nextButton; }
		
		public function setNextButton($button:InteractiveObject): void 
		{
			if(m_nextButton) {
				if(contains(m_nextButton)) removeChild(m_nextButton);
				m_nextButton.removeEventListener(MouseEvent.CLICK, increase );
			}
			m_nextButton = $button;
			addChild(m_nextButton);
			m_nextButton.addEventListener(MouseEvent.CLICK, increase  );
		}
		
	}
}